function unix2time(time) {
    var unixTimestamp = new Date(time*1000);
    var commonTime = unixTimestamp.toLocaleString()
    return commonTime
}

String.prototype.replaceAll  = function(s1,s2) {
    return this.replace(new RegExp(s1,"gm"),s2);   
} 
// 检查是否是金额
function validateMoney(money){
    var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
    if (reg.test(money)) {
         return true;
    }else{
         return false;
    }
}

function error_bar(msg,func=function(){}) {
    Swal.fire({
        icon: 'error',
        title: '似乎哪里出了问题',
        text: msg,
    }).then(function(isConfirm) {
        if (isConfirm.isConfirmed === true) {func()}})
    document.getElementsByClassName('swal2-popup')[0].style.zIndex=99999
}
function success_bar(msg) {
    Swal.fire({
        icon: 'success',
        title: msg,
        showConfirmButton: true,
        timer: 1500
      })
}
function ask_bar(msg,func) {
    Swal.fire({
        title: '操作确认',
        text: msg,
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'YES!'
      }).then((result) => {
        if (result.value) {
          func();
        }
      })
}

// 头可短，血可流，必须保证，每个地方都存在用户数组
var sysuser = new Object()
$.ajax({
    url : "/user/api/list",
    async: false,
    success : function(data) {
        for (i=0; i<data.length; i++) {
            sysuser[data[i].uid] = data[i]
        }
    }
})
var sysposttype = new Object()
var PostType = new Object()
$.ajax({
    url : "/post/api/get/type",
    async: false,
    success : function(data) {
        sysposttype = data
        data.forEach(element => {
            PostType[element.english] = element.chinese
        })
    },
})
function getFacer(doc) {
    doc.src = "/static/img/facer/"+window.localStorage.getItem("uid")+".jpg"
}
function getFacerPath(uid) {
    return "/static/img/facer/"+uid+".jpg"
}
//num = num.toFixed(2);	//替换num即可，整一大段代码都需要写哦

Number.prototype.toFixed = function(d) {
	var s = this + "";
	if(!d) d = 0;
	if(s.indexOf(".") == -1) s += ".";
	s += new Array(d + 1).join("0");
	if(new RegExp("^(-|\\+)?(\\d+(\\.\\d{0," + (d + 1) + "})?)\\d*$").test(s)) {
		var s = "0" + RegExp.$2,
			pm = RegExp.$1,
			a = RegExp.$3.length,
			b = true;
		if(a == d + 2) {
			a = s.match(/\d/g);
			if(parseInt(a[a.length - 1]) > 4) {
				for(var i = a.length - 2; i >= 0; i--) {
					a[i] = parseInt(a[i]) + 1;
					if(a[i] == 10) {
						a[i] = 0;
						b = i != 1;
					} else break;
				}
			}
			s = a.join("").replace(new RegExp("(\\d+)(\\d{" + d + "})\\d$"), "$1.$2");

		}
		if(b) s = s.substr(1);
		return(pm + s).replace(/\.$/, "");
	}
	return this + "";
	
};
